<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
        <script type="text/javascript" src="lib/html5shiv.js"></script>
        <script type="text/javascript" src="lib/respond.min.js"></script>
        <![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" href="./../lib/layui/css/layui.css">
    <link rel="stylesheet" href="./../lib/zTree/v3/css/zTreeStyle/zTreeStyle.css">
    <style>
        .container{
            display: flex;
            /* justify-content: space-between; */
            margin: 0;
            padding: 0;
        }
        .zTreeDemoBackground {
            width: 50%;
            height: auto;
            background: #eee;
            margin-right: 10px;
        }
        .input-text{
            padding: 0;
        }
        .form .cl label{margin-bottom: 5px;}
    </style>
    <!--[if IE 6]>
            <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
            <script>DD_belatedPNG.fix('*');</script>
            <![endif]-->
    <title>团队列表</title>
</head>

<body>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 团队管理 <span
            class="c-gray en">&gt;</span>团队列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
            href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <!-- ztree -->
            <div class="layui-row">
                <div class="layui-col-md4">
                    <div style="background-color:#f2f2f2;padding: 3px;">
                        <ul id="myZtree" class="ztree"></ul>
                    </div>
                </div>
                <div class="layui-col-md7" style="margin-left:20px">
                    <div class="form form-horizontal" id="form-admin-add" style = "display:none">
                        <div class="cl">
                            <!-- <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>ID：<span id="id">0</span></label> -->
                            <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>团队管理者: <span id="teamAdmin">0</span></label>
                            <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>团队下总人数： <span id="teamSumNum">0</span></label>
                            <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>团队下直属人数： <span id="teamNum">0</span></label>
                            <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>个人身份等级： <select class="input-text"
                                    style="width:100px;" id="lv">
                                    <option value="0">大众会员</option>
                                    <option value="1">黄金会员</option>
                                    <option value="2">铂金会员</option>
                                    <option value="3">钻石会员</option>
                                </select>

                            </label>
                            <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>团队礼包等级： <select class="input-text"
                                    style="width:100px;" id="giftBagLv">
                                    <option value="0">无</option>
                                    <option value="1">初级合伙人</option>
                                    <option value="2">中级合伙人</option>
                                    <option value="3">高级合伙人</option>
                                    <option value="4">资深合伙人</option>
                                    <option value="5">功勋合伙人</option>
                                    <option value="6">执行委员</option>
                                    <option value="7">决策委员</option>
                                </select>
                            </label>
                            <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>团队重销等级： <select class="input-text"
                                    style="width:100px;" id="teamReSaleLv">
                                    <option value="0">无</option>
                                    <option value="1">一级</option>
                                    <option value="2">二级</option>
                                    <option value="3">三级</option>
                                    <option value="4">四级</option>
                                </select>
                                <span class="layui-btn layui-btn-sm" onclick="edit()">保存</span>
                            </label>
                            <!-- <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>用户名： <span id="userName">0</span></label> -->
                            <!-- <label class=" col-xs-6 col-sm-6">昵称： <span id="name">0</span></label>
                            <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>手机号：<span id="phone">0</span></label>
                            <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>微信号：<span id="wx">0</span></label>
                            <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>团队礼包等级：<span id="lblv">0</span>
                                <span class="layui-btn layui-btn-sm" onclick="edit(0)">修改</span> </label>
                            <label class=" col-xs-6 col-sm-6"><span class="c-red"></span>团队重销等级：<span id="lv">0</span>
                                <span class="layui-btn layui-btn-sm" onclick="edit(1)">修改</span> </label> -->
                        </div>
                    </div>
                    <table class="layui-hide" id="teamList" lay-filter="teamList"></table>
                </div>
            </div>
    </div>
    </div>
    <input type="" name="details_id" id="details_id" value="" style="display:none;" />
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="./../static/js/common.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <script type="text/javascript" src="./../lib/layui/layui.js"></script>
    <script type="text/javascript" src="./../lib/zTree/v3/js/jquery.ztree.all-3.5.js"></script>

    <!--/_footer 作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/html" id="operation">
        <a  title="修改等级" lay-event="edit" class=""><i class="Hui-iconfont">&#xe6df;</i></a>
    </script>
    <script type="text/javascript">
        var myZtree,
            code = '',
            id = '';
        $(function () {

            myzTree = $.fn.zTree.init($("#myZtree"), setting, zNodes);

        });
        var uCode = '';
        var zNodes;
        var setting = {
            async: {
                enable: true,
                url: admin_url + "/kvmUser/teamZtree",
                autoParam: ["userCode"],
                otherParam: { "token": token, "tokenUserId": userId },
                dataFilter: filter
            },
            check: {
                enable: false,
                autoCheckTrigger: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            edit: {
                enable: false,
                editNameSelectAll: true,
            },
            view: {
                selectedMulti: true,
                nameIsHTML: true,
            },
            callback: {
                beforeClick: function (treeId, treeNode, clickFlag) {
                    return (treeNode.click != false);
                },
                onClick: onClick,
                onAsyncSuccess: updateTreeScrollbar,
                onCollapse: updateTreeScrollbar2,
                onExpand: onClick,
            }
        };

        function onClick(event, treeId, treeNode, clickFlag) {
            // 兼容处理
            if (!treeNode.isParent) {
                $("#insAdd").removeClass("disabled");
            } else {
                $("#insAdd").addClass("disabled");
            }

            var userCode = treeNode.userCode;
            code = userCode;
            // var pollCode = treeNode.pollCode;
            id = treeNode.id;
            $.ajax({
                type: "post",
                xhrFields: { withCredentials: true },
                url: admin_url + '/kvmUser/teamStatisticInfo',
                data: { tokenUserId: userId, token: token, userCode: userCode },
                success: function (data) {
                    if (data.code == 200) {
                        $("#form-admin-add").show();
                        var data = data.data
                        $("#teamAdmin").text(data.teamUserName)

                        $("#teamNum").text(data.teamUserNum)
                        $("#teamSumNum").text(data.teamAllUserNum)
                        if (data.teamGiftLv == null) {
                            $("#giftBagLv").text("")
                        } else {
                            $("#giftBagLv").val(data.teamGiftLv)

                        }
                        $("#teamReSaleLv").val(data.teamProductLv)
                        if (data.lv == null) {
                            $("#lv").text('')
                        } else {
                            $("#lv").val(data.lv)
                        }
                    }
                    layui.use('table', function () {
                        var table = layui.table;
                        table.render({
                            elem: '#teamList',
                            cellMinWidth: 80,
                            // id为重置表格，进行搜索
                            id: 'reload2',
                            url: admin_url + '/kvmUser/teamUserList',
                            request: {
                                pageName: 'page',
                                limitName: 'size',

                            },
                            paresData: function (res) {
                                return {
                                    'data': res.data
                                }
                            },
                            response: {
                                statusCode: 200

                            },
                            where: {
                                tokenUserId: userId,
                                token: token,
                                userCode: userCode
                            },
                            done: function (res, curr, count) {
                            },
                            method: 'post',
                            cols: [[
                                { field: 'userName', title: '用户名' },
                                { field: 'name', title: '真实姓名' },
                                { field: 'mobile', title: '手机号' },
                                { field: 'wx', title: '微信号' }
                            ]],
                            page: true
                        })
                    })
                }
            })
        }

        function updateTreeScrollbar() {


        }

        function updateTreeScrollbar2() {
            
        }

        function filter(treeId, parentNode, childNodes) {
            if (!childNodes) return null;
            // $(".right_content").removeClass('hide')
            return childNodes.data
        };

        function edit() {
            $.ajax({
                type: "post",
                xhrFields: { withCredentials: true },
                url: admin_url + '/kvmUser/teamStatisticInfo',
                data: { tokenUserId: userId, token: token, userCode: code },
                success: function (data) {
                    if (data.code == 200) {
                        if ($("#giftBagLv option:selected").val() == data.data.teamGiftLv && $("#teamReSaleLv option:selected").val() == data.data.teamProductLv && $("#lv option:selected").val() == data.data.lv) {
                        
                        } else {
                            var giftBagLv = $("#giftBagLv option:selected").val(),
                                 teamReSaleLv = $("#teamReSaleLv option:selected").val(),
                                 lv = $("#lv option:selected").val();
                            $.ajax({
                                type: "post",
                                xhrFields: { withCredentials: true },
                                url: admin_url + '/kvmUser/updUserLv',
                                data: { tokenUserId: userId,id:id, token: token,teamGiftLv:giftBagLv,teamProductLv:teamReSaleLv,lv:lv},
                                success:function(data){
                                    if(data.code == 200){
                                        layer.msg('修改成功',{
                                            time:1000,
                                            end:function(){
                                                location.replace(location.href)
                                            }
                                        })
                                    }
                                }
                            })
                        }
                    }
                }
            })


        }

    </script>
</body>

</html>